﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using YwangHRMSys.DBUtility;


public class TrailDaysInfoDAL
    {
        #region 基础方法

        #region 开始生成tomodel提高代码的重用性

        /// 开始生成tomodel提高代码的重用性
        private TrailDaysInfoModel ToModel( DataRow row )
        {
            var model = new TrailDaysInfoModel();
            model.Id = (Guid) SqlHelper.FromDbValue(row["Id"]);
            model.DateEntryTime = (DateTime) SqlHelper.FromDbValue(row["DateEntryTime"]);
            model.DatePositiveTime = (DateTime) SqlHelper.FromDbValue(row["DatePositiveTime"]);
            model.TrailDays = (String) SqlHelper.FromDbValue(row["TrailDays"]);
            model.EmployeeEntry = (String) SqlHelper.FromDbValue(row["EmployeeEntry"]);
            model.EmployeePositive = (String) SqlHelper.FromDbValue(row["EmployeePositive"]);
            return model;
        } //tomodel的结束。

        #endregion

        #region listAll开始

        //查询所有TrailDaysInfo的数据列表
        public IEnumerable <TrailDaysInfoModel> ListAll()
        {
            var list = new List <TrailDaysInfoModel>();
            DataTable table = SqlHelper.ExecuteDataTable
                    (
                            "Select Id,DateEntryTime,DatePositiveTime,TrailDays,EmployeeEntry,EmployeePositive FROM  TrailDaysInfo");
            foreach (DataRow row in table.Rows)
                {
                    TrailDaysInfoModel model = ToModel(row);
                    list.Add(model);
                }
            return list;
        } //listAllTrailDaysInfo结束

        #endregion

        #region  根据ID来查询TrailDaysInfo的信息

        public TrailDaysInfoModel GetByTrailDaysInfoID( Guid Id )
        {
            DataTable table = SqlHelper.ExecuteDataTable
                    (
                            " SELECT Id,DateEntryTime,DatePositiveTime,TrailDays,EmployeeEntry,EmployeePositive FROM  TrailDaysInfo  WHERE  Id = @Id",
                            new SqlParameter("@Id", Id));
            if (table.Rows.Count <= 0)
                {
                    return null;
                }
            if (table.Rows.Count == 1)
                {
                    return ToModel(table.Rows[0]);
                }
            throw new Exception();
        }

        #endregion

        #region  根据ID修改TrailDaysInfo的信息

        public void UpdateTrailDaysInfo( TrailDaysInfoModel model )
        {
            SqlHelper.ExecuteNonQuery
                    (
                            "  UPDATE  TrailDaysInfo SET DateEntryTime = @DateEntryTime,DatePositiveTime = @DatePositiveTime,TrailDays = @TrailDays,EmployeeEntry = @EmployeeEntry,EmployeePositive = @EmployeePositive  WHERE  Id = @Id",
                            new SqlParameter("@Id", model.Id),
                            new SqlParameter("@DateEntryTime", model.DateEntryTime),
                            new SqlParameter("@DatePositiveTime", model.DatePositiveTime),
                            new SqlParameter("@TrailDays", model.TrailDays),
                            new SqlParameter("@EmployeeEntry", model.EmployeeEntry),
                            new SqlParameter("@EmployeePositive", model.EmployeePositive));
        }

        #endregion

        #region 添加TrailDaysInfo信息

        // 添加一条TrailDaysInfo 的信息
        public void InsertTrailDaysInfo( TrailDaysInfoModel model )
        {
            SqlHelper.ExecuteNonQuery
                    (
                            "INSERT INTO TrailDaysInfo  (Id,DateEntryTime,DatePositiveTime,TrailDays,EmployeeEntry,EmployeePositive  ) values (@Id,@DateEntryTime,@DatePositiveTime,@TrailDays,@EmployeeEntry,@EmployeePositive)",
                            new SqlParameter("@Id", model.Id),
                            new SqlParameter("@DateEntryTime", model.DateEntryTime),
                            new SqlParameter("@DatePositiveTime", model.DatePositiveTime),
                            new SqlParameter("@TrailDays", model.TrailDays),
                            new SqlParameter("@EmployeeEntry", model.EmployeeEntry),
                            new SqlParameter("@EmployeePositive", model.EmployeePositive));
        }

        #endregion

        //根据ID来查询TrailDaysInfo的信息

        //根据ID修改TrailDaysInfo的信息

        #endregion
    }

//当前TrailDaysInfoDAL类结束